using Bootstrap.Security;
using Longbow.Cache;
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Bootstrap.DataAccess.Model;
namespace Bootstrap.DataAccess
{
    /// <summary>
    /// 
    /// </summary>
    public static class AnswerHelper
    {
        public const string RetrieveAnswerDataKey = "UserHelper-RetrieveAnswer";
        public const string RetrieveAnswerByRoleIdDataKey = "UserHelper-RetrieveAnswerByRoleId";
        public const string RetrieveAnswerByGroupIdDataKey = "UserHelper-RetrieveAnswerByGroupId";
        public const string RetrieveNewAnswerDataKey = "UserHelper-RetrieveNewAnswer";
        public const string RetrieveAnswerByNameDataKey = "BootstrapUser-RetrieveAnswerByName";

        /// <summary>
        /// 查询所有用户
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<Answer> Retrieves() => CacheManager.GetOrAdd(RetrieveAnswerDataKey,
            key => DbContextManager.Create<Answer>().Retrieves());



        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        public static bool Delete(IEnumerable<string> value)
        {
           
            var ret = DbContextManager.Create<Answer>().Delete(value);            
            return true;
        }


        /// <summary>
        ///  
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static bool Save(Answer an)
        {
            var ret = DbContextManager.Create<Answer>().Save(an);
            //if (ret) CacheCleanUtility.ClearCache(
            //    userIds: string.IsNullOrEmpty(user.Id) ? 
            //    new List<string>() : new List<string>() { user.Id });
            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="password"></param>
        /// <param name="displayName"></param>
        /// <returns></returns>
        public static bool Update(string id, string password, string displayName)
        {

            //if (DictHelper.RetrieveSystemModel())
            //{
            //    var admins = Retrieves().Where(u => u.UserName.Equals("Admin", StringComparison.OrdinalIgnoreCase));
            //    if (admins.Any(v => v.Id == id)) return true;
            //}
            //var ret = DbContextManager.Create<User>().Update(id, password, displayName);
            //if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(id) ? new List<string>() : new List<string>() { id });
            return true;
        }



    }
}
